import React, { Component } from 'react';

import store from './store';

import { sendAction } from './action';

export default class SendActionComponent extends Component {

  componentDidMount() {
    store.subscribe(() => {
      console.log(store.getState());
      this.setState({});
    })
  }

  handleClick = () => {
    const timeNow = new Date().toLocaleTimeString();
    const action = sendAction(timeNow);
    store.dispatch(action);
  }

  render() {
    return (
      <div>
        <h3>仅使用 Redux</h3>
        <button onClick={this.handleClick}>点我发送 action</button>
        <div>{store.getState().value}</div>
      </div>
    )
  }
}